[code]
public class MainActivity extends Activity implements OnClickListener{
public TextView txt;
public Button bttn;
GoogleCloudMessaging gcm;
String PROJECT_NUMBER = "494579369983";
public String regid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = (TextView)findViewById(R.id.txt_id);
bttn = (Button)findViewById(R.id.button_ok);
bttn.setOnClickListener(this);
}
public void getRegId()
{
new AsyncTask<Void, Void, Void>() {
@Override
public Void doInBackground(Void... params) {
try
{
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
}
regid = gcm.register(PROJECT_NUMBER);
txt.setText("Device reg id is: "+regid);
} catch (IOException ex) {
}
return null;
}
@SuppressWarnings("unused")
protected void onPostExecute() {
}
}.execute(null, null, null);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
getRegId();
}
}
[/code]
[code]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.deneme_project"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.example.deneme_project.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.deneme_project.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
[/code]
şu getId yi nasıl alıcam şuan server ile ilgili kodlar yok sadece yapmak istediğim şey regId yi alabilmek